#include "edge.h"
#include "loop.h"
#include "face.h"

Edge::Edge(unsigned int _id) : id(_id){
    he1 = NULL;
    he2 = NULL;
    selected = false;
}

Edge::Edge(unsigned int _id, HalfEdge *_he1, HalfEdge *_he2) : id(_id), he1(_he1), he2(_he2){
    delete he1;
    delete he2;
    selected = false;
}

Edge::~Edge(){
}

void Edge::setHE1(HalfEdge *_he){
        he1 = _he;
}

void Edge::setHE2(HalfEdge *_he){
        he2 = _he;
}

unsigned int Edge::getID(){
    return id;
}

HalfEdge *Edge::getHE1(){
    return he1;
}

HalfEdge *Edge::getHE2(){
    return he2;
}

void Edge::scale(double _s){
    Face *f;
    Vertex *v1 = he1->getStart(), *v2 = he2->getStart();
    Point p1 = v1->getPoint(), p2 = v2->getPoint();
    Point p( (p1.x + p2.x)/2.0, (p1.y + p2.y)/2.0, (p1.z + p2.z)/2.0 );

    p1 = p1 + ((p1 - p).normalization()*_s);
    v1->setPoint( p1 );

    f = he1->getLoop()->getFace();
//    if (f->isBezier()) f->resetBezier();

    p2 = p2 + ((p2 - p).normalization()*_s);
    v2->setPoint( p2 );

    f = he2->getLoop()->getFace();
//    if (f->isBezier()) f->resetBezier();
}

void Edge::translate(Point _t){
    Face *f;
    Vertex *v1 = he1->getStart(), *v2 = he2->getStart();

    Point v = v1->getPoint() + _t;
    v1->setPoint( v );

    f = he1->getLoop()->getFace();
//    if (f->isBezier()) f->resetBezier();

    v = v2->getPoint() + _t;
    v2->setPoint( v );

    f = he2->getLoop()->getFace();
//    if (f->isBezier()) f->resetBezier();
}

void Edge::select(bool _s){
    selected = _s;
}

bool Edge::isSelected(){
    return selected;
}
